
$( init );

var visible;

/**
* Fades the members form out when called
*
* @author Shady
*
*/
function fadeOut() {
    $('#members').fadeOut();
    $('#members').hide();
    $('#background').fadeTo('slow',1);
    $('.removeButtons').fadeTo('slow',1);
    $('#hideButton').fadeTo('slow',1);
    visible = false;
}

function init() {

  // Hide the form initially.
  // Position the form so it sits in the centre of the browser window.
  $('#members').hide().addClass( 'positioned' );
  
  visible = false;

  // When the "Send us feedback" link is clicked:
  // 1. Fade the content out
  // 2. Display the form
  // 3. Move focus to the first field
  // 4. Prevent the link being followed

    /**
    * @author Shady
    * When the button popup is clicked if the form
    * is not visible it will be visible and vice versa
    */
    $('#popup').click( function() 
    
        {
            if (!visible) {
            $('#background').fadeTo( 'slow', .2 );
            $('.removeButtons').fadeTo( 'slow', .2 );
            $('#background').hide();
            $('.removeButtons').hide();
            $('#hideButton').fadeTo( 'slow', .2 );
            $('#hideButton').hide();
            $('#members').fadeIn( 'slow', function(){});
            visible = true;
            return false;
            } else {
            $('#members').fadeOut();
            $('#background').fadeTo('slow',1);
            $('.removeButtons').fadeTo('slow',1);
            $('#hideButton').fadeTo('slow',1);
            visible = false;
            return false;
            }
        }
    
    );

	$('a[href="#members"]').click( function() {
    $('#background').fadeTo( 'slow', .2 );
    $('#members').fadeIn( 'slow', function(){});
   return false;
    });
  
    $('#closeMembers').click(function(){
    $('#members').fadeOut();
    $('#background').fadeTo('slow',1);
  });
  
  $('#background').click(function(){
    $('#members').fadeOut();
    $('#background').fadeTo('slow',1);
  });
  
	$('#members').keydown( function( event ) {
    if ( event.which == 27 ) {	
	 $('#members').fadeOut();
     $('#background').fadeTo('slow',1);
	}
  });
}
